package com.pzhu.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pzhu.model.entity.Order;
import com.pzhu.model.help.PageBean;
import com.pzhu.model.help.ResponseResult;
import com.pzhu.service.OrderService;
import com.pzhu.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author : zqh
 * @Date : 2024/1/4 0004 下午 2:19
 * @Version: 1.0
 */
@Api(tags = "订单接口")
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @ApiOperation("查询所有信息")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody PageBean pageBean){

        String query=pageBean.getQuery().trim();

        Page<Order> pageResult = orderService.page(
                new Page<Order>(pageBean.getPageNum(), pageBean.getPageSize()),
                new QueryWrapper<Order>().like(StringUtil.isNotEmpty(query), "code", query)
                        .orderByAsc("status")
        );

        List<Order> orderList = pageResult.getRecords();


        Map<String,Object> map=new HashMap<>();
        map.put("orderList",orderList);
        map.put("total",pageResult.getTotal());
        return ResponseResult.ok(map);
    }
}
